/*
 * init_lhdfs_file - find the last segment file, read the info of inode map of the last log,
 *                   and initial some key words in the structure ctrl
 * @param ctrl      the pointer that point to the structure ctrl
 * @param uri       the place where is the filesystem palced
 * @param fs_name   the directory named fs_name
 * @return Return the flag whether the function is executed successfully,
 *         0 is success, 1 is failed.
 */
			   
int
init_lhdfs_file(lhdfs_ctrl *ctrl, char *uri, char *fs_name)
{
	char *seg_file_name = NULL;
	struct lhdfs_logheader *log;
	int inode;
		 
	inode = find_latest_segment_file(uri, fs_name);
	seg_file_name = ctrl->inode_fname[inode];
	if (inode < 0)      //it is the 1st fs, doesn't have any file
	{
	     ctrl->last_segment = 0;
	     ctrl->last_offset = 0;
	     ctrl->inode_map[0]->inode_ino = 0;
         ctrl->inode_map[0]->storage_address = 0;
	}
	else
    {
		ctrl->last_segment = get_prefix(seg_file_name);
        ctrl->last_offset = get_file_len(seg_file_name);
		lognum = load_last_log(ctrl);
     
        if(lognum == 0)
	             return -1;
		ctrl->inode_map[0].storage_address = inode_map_address(seg_file_name);
    }

	return 0;
}


